﻿using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class TestHierarchy : MonoBehaviour
{
    [MenuItem("GameObject/Test2",false,0)]
    static void Test2()
    {
        Debug.Log(" test project test2 ");


    }

    [InitializeOnLoadMethod]
    static void InitializeOnLoad()
    {

        EditorApplication.hierarchyWindowItemOnGUI += (instanceID, rect) =>
        {
            //GUI.Button(new Rect(100, 100, 100, 100), "Test1");

            if (Selection.activeObject != null && instanceID == Selection.activeObject.GetInstanceID())
            {

                //string active_guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(Selection.activeObject));

                //if (active_guid == guid && !string.IsNullOrEmpty(active_guid))
                //{
                    rect.x = rect.width - 50;
                    rect.width = 100;
                    if (GUI.Button(rect, "delete"))
                    {
                        GameObject.DestroyImmediate(Selection.activeObject);
                        //AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(Selection.activeObject));
                        //Debug.Log( " 删除文件： " + AssetDatabase.GetAssetPath(Selection.activeObject));
                    }
                //}
            }

        };
    }

}
